package com.banmao.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

// 抽取公共代码
public class RabbitUtil {

    private static final ConnectionFactory connectionFactory;

    static {
        try {
            connectionFactory = new ConnectionFactory();
            // 连接信息
            connectionFactory.setHost("47.106.133.98");
            connectionFactory.setPort(5672);
            // 登陆用户
            connectionFactory.setUsername("banmao");
            connectionFactory.setPassword("KarlSmith");
            // 虚拟主机
            connectionFactory.setVirtualHost("/test");

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static final Connection getConnection() throws Exception {
        // 创建 TCP 物理连接
        Connection conn = connectionFactory.newConnection();
        return conn;
    }

}
